namespace EyeOpen.Warehouse.Data
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Data.Entity;
	using System.Linq;
	using System.Linq.Expressions;

	internal class Repository<T> : IRepository<T>
		where T : class
	{
		private readonly IDbSet<T> set;
		private readonly IQueryable<T> query;

		public Repository(IDbSet<T> set)
		{
			this.set = set;
			query = set.AsQueryable();
		}

		public Expression Expression
		{
			get
			{
				return query.Expression;
			}
		}

		public Type ElementType
		{
			get
			{
				return query.ElementType;
			}
		}

		public IQueryProvider Provider
		{
			get
			{
				return query.Provider;
			}
		}

		public void Add(T item)
		{
			set.Add(item);
		}

		public void Remove(T item)
		{
			set.Remove(item);
		}

		public IEnumerator<T> GetEnumerator()
		{
			return query.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
}